<?php

if (!defined('INDEX')) exit;

require("common/functions_jcas_modules.php");

?>

<table width="100%"  border="0" cellspacing="0" cellpadding="2">

  <tr>

    <td class="datatd" bgcolor="#FFFFFF"><?php echo $lang['config_desc']?></td>

  </tr>

</table>

<br />

<?php

####### ACTIONS ########

// Add new variable

echo config_insert();

// Edit variable

echo config_update();

// Set value for field

echo common_set_value($tbl['site_config'],'id');

// Delete variable

echo common_delete($tbl['site_config'],'id');

// Delete selected variables

echo common_delete_selected($tbl['site_config'],'id');

// Update variable

echo common_update_sort($tbl['site_config'],'id','sort');

// Active selected

echo common_activate_selected($tbl['site_config'],'id','active');

// Deactive selected

echo common_deactivate_selected($tbl['site_config'],'id','active');



if($show_content)

{

?>

		<table width="100%"  border="0" cellspacing="0" cellpadding="0">

	  <tr>

		 <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">

			<tr>

			  <td width="120" class="<?php echo ((@$_GET['p']=='show')?'tabtd':'tabtd_blur')?>" align="center"><a href="<?php echo $index_url?>&p=show"><?php echo $lang['manage_configs']?></a></td>

			  <td width="5">&nbsp;</td>

			  <td width="120" class="<?php echo ((@$_GET['p']=='add')?'tabtd':'tabtd_blur')?>" align="center"><a href="<?php echo $index_url?>&p=add"><?php echo $lang['add_config']?></a></td>

			  <td width="5">&nbsp;</td>

			  <td >&nbsp;</td>

			</tr>

		 </table></td>

	  </tr>

	  <tr>

		 <td class="tabtd" height="5"></td>

	  </tr>

	</table>

<?php

switch(@$_GET["p"])

{

	case "show":

	default:

		$q_config = @$DB->query('SELECT * FROM '.$tbl['site_config'].' ORDER BY sort ASC, created_time DESC');

		$num_config = $DB->num_rows($q_config);

		?>



		<table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">

		<form name="frm_show" method="post" action="<?php echo $index_url?>&p=show">

			<tr>

				<td colspan="20" class="headtd"><?php echo $lang["site_configs_title"]?></td>

			</tr>

			<tr align="center">

				<td width="20"  class="subheadtd"><?php echo $lang['order']?></td>

				<td width="20"  class="subheadtd"><?php echo $lang['id']?></td>

				<td class="subheadtd"><?php echo $lang['title']?></td>

				<td  class="subheadtd"><?php echo $lang['field']?></td>

				<td  class="subheadtd"><?php echo $lang['value']?></td>

				<td width="40" class="subheadtd"><?php echo $lang['sort']?></td>

				<td width="50" class="subheadtd"><?php echo $lang['active']?></td>

				<td width="80" class="subheadtd"><?php echo $lang['date']?></td>

				<td width="60" class="subheadtd"><input type="checkbox" name="all_id" class="box" value="all" onClick="set_all_cb('frm_show','id[]','all_id');" title="<?php echo $lang['check_uncheck_all']?>"></td>

			</tr>

			<?php

			if($num_config)

			{

				$no = 0;

				for($x=0;$x<$num_config;$x++)

				{

					$no += 1;

					$config = $DB->result_array($q_config,$x,"id,admin_id,sort,title,field,value,value_en,value_fr,created_by,created_time,updated_by,updated_time,active");

					$config_title = common_status_title($config['created_by'], timestamp($config['created_time']), $config['updated_by'], timestamp($config['updated_time'])); 

					$row_color = (!$config['active'])?'bgcolor="#EEEEEE"':'';

					?>

					<tr  onMouseOver="rollon(this);" onMouseOut="rolloff(this);" <?php echo $row_color?>>

						<td align="right" class="datatd"><?php echo $no?></td>

						<td align="right" class="datatd"><font color="red"><?php echo $config['id']?></font></td>

						<td class="datatd"><a href="<?php echo $index_url?>&p=edit&id=<?php echo $config['id']?>" title="<?php echo $config_title?>"><b><?php echo $config['title']?></b></a></td>

						<td class="datatd"><font color="red"><?php echo $config['field']?></font></td>

						<td class="datatd"><?php echo $config['value']?></td>

						<td align="center" class="datatd"><input type="text" name="sort[<?php echo $config['id']?>]" size="3" value="<?php echo $config['sort']?>" style="color:#FF0000; text-align:right" /></td>

						<td align="center" class="datatd">

							 <?php echo html_yes_no($config['active'],'active',$index_url.'&p=show&id='.$config['id']) ?>

						</td>

						<td align="center" class="datatd"><?php echo show_date($cfg['date_format'],timestamp($config['created_time']))?></td>

						<td align="center" class="datatd">

							<?php echo html_icon_edit($index_url.'&p=edit&id='.$config['id']) ?>

							<?php echo html_icon_delete($index_url.'&p=show&act=delete&id='.$config['id']) ?>

							<?php echo html_input_checkbox('id',$config['id']) ?>

						</td>

				  </tr>

				<?php

				 }

			}

			else 

			{

				?><tr>

					 <td colspan="20" align="center" class="datatd"><?php echo message($lang['no_requested_data'],'info')?></td>

				  </tr>

				<?php

			}

			?>

			<tr>

				 <td colspan="20">

					 	<table width="100%"  border="0" cellpadding="0" cellspacing="0">

						<tr align="center">

						  <td  align="right" class="row1td">&nbsp;</td>

							 <td width="10%" class="row1td"><input type="submit" name="update_sort" value="<?php echo $lang["update_sort"]?>" class="button"></td>

						  <td width="10%" class="row1td"><?php echo common_action_list()?></td>

						</tr>

					  </table>

						

					 </td>

				  </tr>

				  <input type="hidden" name="session_id" value="<?php echo session_id()?>">

		  </form>

</table>

		<?php

		break;

		

		case "add":

		case "edit":

		$config = $DB->fetch_array($DB->query('SELECT * FROM '.$tbl['site_config'].' WHERE id="'.$_GET['id'].'"'));

		echo js_validate("title,field,value","frm_add");

		?>

		<table width="100%"  border="0" cellspacing="0" cellpadding="0" align="center">

				<form name="frm_add" method="post" action="<?php echo $index_url?>&p=add&id=<?php echo $_GET['id']?>" onSubmit="return validate_frm_add();">

				  <tr>

					 <td colspan="2" class="headtd"><?php echo (($config)?$lang['edit_config']:$lang['add_config'])?></td>

				  </tr>

				  <tr >

					 <td width="30%" class="row1td"><b><?php echo $lang['title']?> </b>*</td>

				  <td width="70%" class="row2td"><input name="title" type="text" style="width:60%" value="<?php echo (($config)?$config["title"]:post("title"))?>" ></td>

				  </tr>

				  
				
					
				 <tr >

					 <td class="row1td"><b><font color="#CC0000"><?php echo $lang['field']?></font></b> *</td>

					 <td class="row2td"><input name="field" type="text" style="width:40%" <?php if($_GET['p']=='edit') echo "readonly"; ?> value="<?php echo (($config)?$config["field"]:post("field"))?>" ></td>

				  </tr>				  				    

				
				  <tr >

				    <td class="row1td" valign="top"><b><font color="#003399"><?php echo $lang['value']?></font></b> *</td>

				    <td class="row2td"><textarea name="value" type="text" style="width:60%" rows="5"><?php echo (($config)?$config["value"]:post("value"))?></textarea></td>

			      </tr>

				  

				  <tr >

				    <td class="row1td" valign="top"><b><font color="#003399"><?php echo $lang['value_en']?></font></b> *</td>

				    <td class="row2td"><textarea name="value_en" type="text" style="width:60%" rows="5"><?php echo (($config)?$config["value_en"]:post("value_en"))?></textarea></td>

			      </tr>

				  <tr >

				    <td class="row1td" valign="top"><b><font color="#003399"><?php echo $lang['value_fr']?></font></b> *</td>

				    <td class="row2td"><textarea name="value_fr" type="text" style="width:60%" rows="5"><?php echo (($config)?$config["value_fr"]:post("value_fr"))?></textarea></td>

			      </tr>

				  <tr >

				    <td valign="top" class="row1td"><b><?php echo $lang['note']?></b></td>

				    <td class="row2td"><input name="note" style="width:60%" value="<?php echo (($config)?$config["note"]:post("note"))?>" /></td>

			      </tr>

				  

				  <tr>

					 <td valign="top" class="row1td"><b><?php echo $lang['active']?></b></td>

					 <td class="row2td"><input type="checkbox" class="box"  name="active" value="1"  <?php echo (($config)?(($config['active'])?'checked=true':''):'checked=true')?> /></td>

				  </tr>

				  

				  <tr>

					 <td colspan="2" align="center" valign="top" class="row2td">

					 <?php if($config) { ?>

					 	 <input type="submit" name="update" class="btn_bg btn_update" value="<?php echo $lang['btn_update']?>">

						 <input type="reset"  class="btn_bg btn_reset" value="<?php echo $lang['btn_reset']?>">

					 <?php } else { ?>

					  	<input type="submit" name="insert" class="btn_bg btn_insert" value="<?php echo $lang['btn_insert']?>">

					 <?php } ?>					 </td>

				  </tr>

					 <input type="hidden" name="session_id" value="<?php echo session_id()?>">

		  </form>

				</table>

			<?php

	break;

}// end switch

}// end show_content

$_GET["p"] = false;

?>